from flask import Flask, render_template
import pandas as pd

app = Flask(__name__)

# 假设 Excel 文件名为 data.xlsx，放在项目根目录
EXCEL_FILE = 'data.xlsx'

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/get_data/<category>')
def get_data(category):
    try:
        df = pd.read_excel(EXCEL_FILE, sheet_name=category)
        # 这里需要根据实际的分类列名和分类值进行数据筛选
        # 示例：假设数据中有 'category' 列
        filtered_data = df
        return filtered_data.to_json(orient='records')
    except Exception as e:
        return str(e), 500

if __name__ == '__main__':
    app.run(debug=True)